import os
import yaml

import googlesearch

"""
google 搜索工具

pip install google
pip install pyyaml

todo 与浏览器结合
"""

def get_yaml_data(yaml_file):
    file = open(yaml_file, 'r', encoding="utf-8")
    file_data = file.read()
    file.close()
    data = yaml.load(file_data)
    return data


if __name__=="__main__":
    current_path = os.path.abspath(".")
    yaml_path = os.path.join(current_path, "config.yaml")
    config = get_yaml_data(yaml_path)
    # 输入的关键词
    query = ""
    search_result = googlesearch.search(query, tld='com', lang='en', tbs='0', safe='off', num=10, start=0, stop=None, pause=2.0, country='', extra_params=None, user_agent=None, verify_ssl=True)
    print(search_result)
